var downLoadUrl = window.AppData.config.baseUrl.Site + 'uploads/printPlug/'; //todo 配置下载地址

//====页面引用CLodop云打印必须的JS文件：====
if (needCLodop()) {
    var head = document.head || document.getElementsByTagName("head")[0] || document.documentElement;
    
	var oscript = document.createElement("script");
	oscript.src ="http://localhost:8000/CLodopfuncs.js?priority=1";
	head.insertBefore( oscript,head.firstChild );

    //引用双端口(8000和18000）避免其中某个被占用：
	oscript = document.createElement("script");
	oscript.src ="http://localhost:18000/CLodopfuncs.js?priority=0";
	head.insertBefore( oscript,head.firstChild );
};

//====获取LODOP对象的主过程：====
function getLodop(errCB){
    var timestamp = Date.parse(new Date());
    timestamp = timestamp / 1000;
    var fileName = "CLodop_Setup_for_Win32NT.exe?timeStamp="+timestamp;
    var strCLodopInstall="<br> <span translate>打印服务插件未安装，请下载安装后请刷新页面。</span> <br><a href='"+ downLoadUrl + fileName + " '  target='_self'><font color='#5e8af5'>[点击下载]</font></a>";
    var strCLodopUpdate="<br>打印服务插件需升级！点击这里<a href='"+ downLoadUrl + fileName + "' target='_self'><font color='#5e8af5'>执行升级</font></a>，升级后请刷新页面。";
    let LODOPINS;
    try{
        try{ LODOPINS=getCLodop();} catch(err) {};
        if (!LODOPINS && document.readyState!=="complete") {errCB("打印插件还没准备好，请稍后再试！"); return null};
        if (!LODOPINS) {
        	errCB(strCLodopInstall);
        	return null;

        }
		if (CLODOP.CVERSION<"2.0.6.8") {
        	errCB(strCLodopUpdate);
		}
        LODOPINS.SET_LICENSES("南京百氪汇信息网络有限公司", "586ADF8AF4E17DEBE36DD1F3BA83CAFE", "", "");
        return LODOPINS;
    } catch(err) {errCB("getLodop出错:"+err);};
};

function needCLodop(){
    return true;
};
